package org.cerberus.platform.components;

import org.cerberus.platform.api.IPlatform;
import org.cerberus.platform.api.IPlatformContext;
import org.cerberus.platform.api.PAttribute;
import org.cerberus.platform.api.PEvent;
import org.cerberus.platform.api.PComponent;
import org.cerberus.platform.api.PInject;
import org.cerberus.platform.client.annotations.InjectClientContext;

import static org.cerberus.platform.api.PlatformUtilities.*;

@PComponent(classID="default.PAction")
public abstract class PAction {

	@PAttribute
	private String title;
	
	@PAttribute
	private String description;
	
	@PAttribute
	private boolean enabled;
	
	@PAttribute
	private boolean visible;
	
	@PAttribute
	private boolean selected;
	
	@PInject
	private IPlatform currentPlatformInstance;
	
	@PInject
	private IPlatformContext currentPlatformContext;
	
	public PAction() {
		inject(this);
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		String oldVal = this.title;
		this.title = title;
		change(this, "title", oldVal, title);
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		String oldVal = this.description;
		this.description = description;
		change(this, "description", oldVal, description);
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		boolean oldVal = this.enabled;
		this.enabled = enabled;
		change(this, "enabled", oldVal, enabled);
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		boolean oldVal = this.visible;
		this.visible = visible;
		change(this, "visible", oldVal, visible);
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		boolean oldVal = this.selected;
		this.selected = selected;
		change(this, "selected", oldVal, selected);
	}

	public static PAction createEventAction(Object component, String eventName) {
		return null;
	}
	
	@PEvent
	public abstract Object perform() throws Throwable;
	
	public void updateState() {
		// defaultl implementation does nothing
	}
}
